package com.intellagric.controller.module.ift_network;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.IftNetworkType;
import com.intellagric.service.iftmonitor.ift_network.NetworkTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/12/10
 * @DESC： 网路类型管理
 */
@Controller
public class NetWorkTypeController {

    @Autowired
    private NetworkTypeService networkTypeService;

    /**
     * 添加网路类型信息
     * @Param networkType
     * @return ResponseMessage
     */
    @RequestMapping("/network/type/add")
    @ResponseBody
    public ResponseMessage add(IftNetworkType networkType) {
        networkType.setId(UUID.randomUUID().toString().replaceAll("-",""));
        networkType.setCreateDate(new Date());
        networkType.setUpdateDate(new Date());
        return networkTypeService.addNetworkType(networkType);
    }


    /**
     * 删除网路类型信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/network/type/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return networkTypeService.deleteNetworkType(id);
    }

    /**
     * 修改网路类型信息
     * @Param networkType
     * @return ResponseMessage
     */
    @RequestMapping("/network/type/edit")
    @ResponseBody
    public ResponseMessage edit(IftNetworkType networkType) {
        networkType.setUpdateDate(new Date());
        return networkTypeService.editNetworkType(networkType);
    }

    /**
     * 查询网路类型信息
     * @return networkType
     */
    @RequestMapping("/network/type/{id}")
    @ResponseBody
    public IftNetworkType get(@PathVariable String id) {
        return networkTypeService.getNetworkTypeById(id);
    }

    /**
     * 查询网路类型树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/network/type/tree")
    @ResponseBody
    public LayuiDataGridResult getTree() {
        return networkTypeService.getNetworkTypeTree();
    }

    /**
     * 查询网路类型树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/network/type/tree/select")
    @ResponseBody
    public List<IftNetworkType> getTreeSelect() {
        return networkTypeService.getNetworkTypeTree().getData();
    }

}
